package com.FundamentalDemos.Operator;

public class 逻辑运算符 {
    public static void main(String[] args) {
        double size = 5;
        int storage = 16;

        boolean rs = size >= 6 & storage >= 8;//逻辑与
        System.out.println(rs);

        rs = size >= 6 | storage >= 8;//逻辑或
        System.out.println(rs);

        System.out.println(!true);//逻辑非
        System.out.println(!false);

        System.out.println(!(2 > 1));

        //^异或,一真则真,全假为假,全真也为假
        System.out.println(true ^ true);
        System.out.println(false ^ false);
        System.out.println(false ^ true);
        System.out.println(true ^ false);

        int temp = 1;
        //&&短路与,一旦发现假,则不再执行后面代码
        System.out.println(2 > 10 && (temp++ == 1));
        System.out.println("temp=" + temp);

        //||短路或,一旦发现真,则不再执行后面代码
        System.out.println(2 > 1 || (temp++ == 1));
        System.out.println("temp=" + temp);

        int i, j, k;
        i = 1;
        j = 2;
        k = 3;
        System.out.println("最大值是:" + (i > j ? (i > k ? i : k) : (j > k ? j : k)));


//        括号/成员运算符>单目运算符>算术运算符>关系运算符>逻辑运算符>条件运算符(三目)>赋值运算符
//        &&的优先级高于||
        System.out.println(10 > 3 || 10 > 3 && 10 < 3);//true
        System.out.println((10 > 3 || 10 > 3) && 10 < 3);//false


    }
}
